package com.smartwork.common.sms.aliyun;

import com.smartwork.common.config.Global;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AliYunUtil {

    private static Logger log = LoggerFactory.getLogger(AliYunUtil.class);

    private static final String url = Global.getConfig("ali_sms_url");// 应用地址
    private static final String app_key = Global.getConfig("ali_sms_app_key");// 账号
    private static final String secret = Global.getConfig("ali_sms_secret");// 密码
    private static final String sms_type = "normal";



    public static void sendMsg(final String mobile, final String message, final String templateCode,final  String freeSignName) {
        new Thread(){
            @Override
            public void run() {
                TaobaoClient client = new DefaultTaobaoClient(url, app_key, secret);
                AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
                req.setSmsType(sms_type);
                req.setSmsFreeSignName(freeSignName);
                req.setSmsParamString(message);
                req.setRecNum(mobile);
                req.setSmsTemplateCode(templateCode);
                try {
                    AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
                    System.out.println(rsp.getBody());
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }.start();
    }

}
